/**
 * 
 */
package com.base.myproject.client.busi.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BaseStoreEvent;
import com.base.myproject.client.busi.BaseStoreListener;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.busi.ccode.NewCCode;
import com.base.myproject.client.busi.print.PrintDialogX;
import com.base.myproject.client.busi.print.Printer;
import com.base.myproject.client.busi.system.BcodeChecker;
import com.base.myproject.client.busi.system.BcodeSync;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.system.BaseResource;
import com.base.myproject.client.system.Env;
import com.base.myproject.client.system.SystemMessage;
import com.base.myproject.client.tools.Debug;
import com.base.myproject.client.ui.BaseBusiLeftPanel;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.base.myproject.client.ui.celleditor.BaseGridEditor;
import com.base.myproject.client.ui.codenamemap.CodeNameMapFactory;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.FieldEvent;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.store.StoreEvent;
import com.extjs.gxt.ui.client.store.StoreListener;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.AggregationRowConfig;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
import com.extjs.gxt.ui.client.widget.grid.SummaryType;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.extjs.gxt.ui.client.widget.tips.ToolTipConfig;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.xml.client.Element;

/**
 * 会员正在接受服务的录入界面，主要做查询会员号， 登记正在接受服务的会员和接受服务内容
 * 和ServiceListing比添加了考核部分的处理
 * @author zgw 2009-10-7 下午06:40:13 javazgw@gmail.com
 */
public class ServiceListingX extends BaseJDBCPanel implements
		Listener<BaseEvent> ,BaseStoreListener,Printer,AsyncCallback<Associator> {

	BaseStore<BusiObject> store = null;
	BaseStore<BusiObject> s_service_po_g_store ;
	final NumberFormat currency = NumberFormat.getCurrencyFormat();
	final NumberFormat number = NumberFormat.getFormat("0.00");
	Button endbutton;
	Button paidbutton;
	Button startbutton;
	Button printer;
	Button associatorbutton;
	Button changedpo;
	Button addfinance;
	Button associate; //交接按钮
	Button newccode;
	
	Button addnew; //添加新单据按钮
//	NumberField Accounts ;
//	NumberField Paid ;
	NumberField pay ;
	NumberField pay_g ;
	TextField<String> docname = new TextField<String>();
	DateField servicestartdate ;
	DateField serviceenddate;
	DateField createdate ;
	NumberField peoplenum ;
	BaseGrid basegrid;
	BaseGrid s_service_po_g_grid ;
	ContentPanel service_panel ;

	VerticalPanel vpanel;
	ColumnConfig bcode;
	
	BaseStore bcode_rander_store;
	
	TextField<String> s_cardnothis;
	//BaseComboBoxForm<ModelData> ccode ;
	TextField<String> ccode;
	TextField<String> roomno ;
	TextField<String>  cname_t, s_mobil; 
	Label aslabel;
	CheckBox  check_isas = new CheckBox();  
	
	BaseFormPanel bfp;
	
	NumberField html=new NumberField();
//	Associator associator=null;
	
	FieldSet fieldSet_isas ;
	Button getassoc_button ;
	BaseGridEditor bgeserviceitem;// 服务类型，在form中
	NumberField service_qty;// 数量，在form中
	NumberField service_upric;// 单价。在form中
	NumberField service_total;// 应收 在form中
	NumberField service_realtotal;//实际收款 在form中
	public ServiceListingX() {
		
		super();
		init();
		// this.setScrollMode(Scroll.AUTO);
	}

	public void init() {
		
		//getToolbarll().add(e)
		
		initRenderStore();
		
		
		busi = SystemMessage.busi[8];
		this.setWidth("1024px");
		//this.setHeight("720px");
		this.setAutoHeight(true);
		
		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
		centerData.setMargins(new Margins(5, 5, 0, 0));
		this.add(initWeigetx(), centerData);

		registerMainStore(store);
		registerStore(store);

		this.setBusino(busi);
		setdefault();
		store.addBaseStoreListener(BaseStoreEvent.EventType.ROW_CHANGED, this);
		

		
	}
	public void complete()
	{
	
		//工具栏菜单
		getToolbarll().add(addnew);
		getToolbarll().add(paidbutton);
		getToolbarll().add(printer);
		//getToolbarll().add(associatorbutton);
		//getToolbarll().add(addfinance);
		getToolbarll().add(associate);
		getToolbarll().add(newccode);
	//	initToolBarItems();
		super.complete();
	}
	/**
	 * 加载渲染的码名映射，在节目初始化之前完成否则界面显示的是码
	 */
	void initRenderStore()
	{



			 //装入ccode的store
			 CodeNameMapFactory
				.getBaseccodestore();
			
	}

	private void setdefault() {
		/*
		 * if(store!=null) { store.addDefault("busicode", busi);
		 * store.addDefault("bcode", Env.getEnvbcode()); }
		 */
		

		
		
		store.addDefault("bcode", Env.getEnvbcode()); 

		store.addDefault("busicode", busi);
		
	}

	private Widget initWeigetx()
	{
		vpanel = new VerticalPanel();
		HorizontalPanel h= new HorizontalPanel();
		vpanel.setHorizontalAlign(HorizontalAlignment.LEFT);
		h.setVerticalAlign(VerticalAlignment.TOP);
		
		
		ContentPanel cpleft = CreateCcodeLeftPanel();
		 changedpo = new Button("修改此单据");
		cpleft.setTopComponent(changedpo);
		changedpo.addListener(Events.Select, this);
		
		 CreateButtonGroup();
		 h.add(cpleft);
		 vpanel.add(createService());
		 vpanel.add(createServiceItem());
			
		 vpanel.add(initserviceitemform());
			h.add(vpanel);
			h.setSpacing(5);
			return h;
			
		
	}
//	public ContentPanel initWeiget() {
//		ContentPanel panel = new ContentPanel();
//		panel.setHeaderVisible(false);
//		panel.setLayout(new BorderLayout());
//		BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 350);
//		westData.setSplit(true);
//		westData.setCollapsible(true);
//		westData.setMargins(new Margins(5));
//		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
//		centerData.setMargins(new Margins(5));
//		
//		ContentPanel cpleft = CreateCcodeLeftPanel();
//		 changedpo = new Button("修改此单据");
//		cpleft.setTopComponent(changedpo);
//		changedpo.addListener(Events.Select, this);
//		panel.add(cpleft, westData);
//		//CreateCcodeLeftPanel();
//		 vpanel = new VerticalPanel();
//	
////		 AssociatorPanel associatorpanel = new AssociatorPanel();
//		 CreateButtonGroup();
//	//	 vpanel.add(CreateButtonGroup());
////		 vpanel.add(associatorpanel);
//		vpanel.add(createService());
//		vpanel.add(createServiceItem());
//		
//		vpanel.add(initserviceitemform());
//		
//		panel.add(vpanel, centerData);
//		//panel.setAutoWidth(true);
//		panel.setHeight("460");
//		//----------
//		//panel.add(vpanel, westData);
//		//BaseMainPanel.getInstance().setHeight("760");
//		return panel;
//	}

	public ContentPanel CreateCcodeLeftPanel() {
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		ColumnConfig icode = new ColumnConfig("icode", "单号", 40);
		
		//columns.add(icode);
//		columns.add(new ColumnConfig("ccode	", "ccode", 50));
//		columns.add(new ColumnConfig("roomno", "roomno", 50));
		ColumnConfig busistatus = new ColumnConfig("busistatus", "状态", 40);
		
		GridCellRenderer<ModelData>	renderer = new GridCellRenderer<ModelData>() {

		      public String render(ModelData model, String property, ColumnData d, int rowIndex,
		          int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {

		       if(model.get(property)==null)
		        return "" ;

		       if(model.get(property).equals("131072"))
		           return "" + ("<img src='images/baseimage/money_yen.png' />" );
		       else if(model.get(property).equals("524288"))
		       	   return "" + ("<img src='images/baseimage/icon-complete.gif' />" );
		       return "" + ("<img src='images/baseimage/cut.png'/>" );
		      // return SystemMessage.getstatus(model.get(property)+"");
		      }
		    };
		    busistatus.setRenderer(renderer) ;
		columns.add(busistatus);
//		columns.add(new ColumnConfig("cname", "会员名", 50));
//		columns.add(new ColumnConfig("s_mobil", "电话", 80));
		columns.add(new ColumnConfig("docname", "单据名称", 100));
/*		ColumnConfig servicestartdate = new ColumnConfig("servicestartdate", "servicestartdate", 50);

		columns.add(servicestartdate);*/
		//ColumnModel cm = new ColumnModel(columns);

		// --set modetype
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.addField("busicode");
		type.addField("bcode");
		type.addField("ccode");
		type.addField("busistatus");
		type.addField("vprepare");
		type.addField("predate");
		type.addField("modifydate");
		type.addField("codename");
		type.addField("odate");
		type.addField("mark");

		type.addField("peoplenum");
		type.addField("Accounts");
		type.addField("Paid");
		type.addField("servicestartdate");
		type.addField("serviceenddate");
		type.addField("roomno");
		type.addField("s_cardno");
		//type.addField("check_isas");
		type.addField("createdate");
		
		type.addField("cname");
		type.addField("s_mobil");
		type.addField("lastfiannce");
		type.addField("pay");
		type.addField("pay_g");
		type.addField("docname");
		
		type.getField("pay").setType(Double.class);
		type.getField("pay_g").setType(Double.class);
		type.getField("Accounts").setType(Double.class);
		type.getField("Paid").setType(Double.class);
		type.getField("peoplenum").setType(Integer.class);
		type.getField("servicestartdate").setType(Date.class);
		type.getField("serviceenddate").setType(Date.class);
		//type.getField("check_isas").setType(Boolean.class);
		type.getField("lastfiannce").setType(Double.class);
		
		StoreInfo info = new StoreInfo();
		info.setTablename("s_service_po");
		info.setKeyname(new String[] { "icode","busistatus" });
		info.setSql("select * from s_service_po where DATEDIFF(day, getdate(), createdate)=0 and bcode='"+Env.getEnvbcode()+"'");
		// info.setKeyname(new String[] { "codename" });

		BaseBusiLeftPanel<BusiObject> basbusileftpanel = new BaseBusiLeftPanel<BusiObject>(columns,
				type, info)
		{
			protected boolean Select(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {
				for (int i = 0; i < type.getFieldCount(); i++) {
					
					Object name = record.get(type.getField(i).getName());
				//状态用了码名映射，所以要对名字进行搜索
					if(type.getField(i).getName().equals("busistatus"))
					{
						if(name!=null && SystemMessage.getstatus(name+"").indexOf(filter.toLowerCase()) !=-1)
						{
							return true;
						}
						
					}
					
					else if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
						return true;
					}
				}
				return false;
			}
			
			public boolean candeleterecord()
			{
				if(this.getStore().getCount()<=0)
				{
					return false;
				}
				if(this.getStore().getValue("busistatus").equals("131072"))
				{
				MessageBox.alert("警告", "不能被删除，因为已经被收银。",	null);
				return false;
				
				}
				return true;
			}
			
			public void doBeforeRowChangeGrid()
			{
				if(store.isIschanged() || s_service_po_g_store.isIschanged() )
				{
					
					GWT.log("doBeforeRowChangeGrid", null);
					  store.trySave();
//					//推迟保存。
//					 DeferredCommand.addCommand(new Command(){
//					      public void execute() {
//					    	  GWT.log("save-----",null);
//					    	  store.trySave();
//					      }
//					    });
					
				}
				
			}
			
			public void setdefault()
			{
				DateTimeFormat activeFormat = DateTimeFormat
				.getFormat("yyyy-M-d H:mm:ss");
				
				store.addDefault("createdate",activeFormat.format(new Date()));
			}
		};
		store = basbusileftpanel.getStore();
		store.addDefault("busistatus","128");
		store.applyFilters("131072");
		basbusileftpanel.getGrid().setAutoExpandColumn("createdate");
		basbusileftpanel.getGrid().setWidth("320");
		basegrid = basbusileftpanel.getGrid();
		setMaincomponent(basegrid);
		return basbusileftpanel.getPanel();
	}

	void CreateButtonGroup()
	{
		
		addnew =  new Button("添加新收银");
		addnew.addListener(Events.Select, this);
		addnew.setId("add_new_service");
		//addnew.setIconStyle("addrecord16");
		addnew.setIcon(AbstractImagePrototype.create(BaseResource.INSTANCE.addrecord()));
		
		startbutton = new Button("开始服务");
		startbutton.addListener(Events.Select, this);
		startbutton.setId("start_service");
		//startbutton.setIconStyle("time_end");
		
		endbutton = new Button("结束服务");
		endbutton.setId("time_start");
		endbutton.addListener(Events.Select, this);
		//endbutton.setIconStyle("time_start");
		
		
		paidbutton = new Button("收银");
		paidbutton.setId("money_yen");
		paidbutton.addListener(Events.Select, this);
		paidbutton.setIconStyle("money_yen");
		paidbutton.setIcon(AbstractImagePrototype.create(BaseResource.INSTANCE.money_yen()));
		
		printer   = new Button("打印");
		//printer.setStyleName("printer");
		//printer.setIconStyle("printer");
		//printer.setId("printer");
		printer.setIcon(AbstractImagePrototype.create(BaseResource.INSTANCE.print_16()));
		
		printer.addListener(Events.Select, this);
		
		associatorbutton= new Button("会员");
		//printer.setStyleName("printer");
		associatorbutton.setIconStyle("associator");
	//associatorbutton.setId("end_service");
		associatorbutton.addListener(Events.Select, this);
		ToolTipConfig ttc=new ToolTipConfig("提示","查询会员信息");
		
		
		associatorbutton.setToolTip(ttc);
		
		
		
		addfinance = new Button("会员充值");
		
		addfinance.addListener(Events.Select, this);
		//addfinance.setIconStyle("money_yen");
		
		associate= new Button("打印交接单");
		
		associate.addListener(Events.Select, this);
		//associate.setIconStyle("time_end");
		associate.setIcon(AbstractImagePrototype.create(BaseResource.INSTANCE.time_end()));
		
		newccode = new Button("添加新会员");
		newccode.setIcon(AbstractImagePrototype.create(BaseResource.INSTANCE
				.contact24()));
		newccode.addListener(Events.Select, this);
		//associatorbutton.getToolTip().show();
		
//		HorizontalPanel hpanel = new HorizontalPanel();
//		//hpanel.add(startbutton);
//		//hpanel.add(endbutton);
//		hpanel.add(paidbutton);
//		hpanel.add(printer);
//		hpanel.add(associatorbutton);
//		hpanel.add(addfinance);
//		return hpanel;
	}
	/**
	 * 头部界面，主界面
	 */
	ContentPanel createService() {
		 service_panel = new ContentPanel();
		 service_panel.setBodyBorder(false);
		 bfp = new BaseFormPanel(store);
		
		TableLayout tl = new TableLayout(6);
		tl.setWidth("600");
		
		bfp.setLayout(tl);
		bfp.setHeaderVisible(false);
		 
//		BaseFormPanel leftpanel = new BaseFormPanel(store);
//		leftpanel.setLayout(new FormLayout());
//		FormData fd = new FormData(200, 30);
//		leftpanel.setHeaderVisible(false);
//		leftpanel.setBodyBorder(false);
//
//		BaseFormPanel rightpanel = new BaseFormPanel(store);
//		rightpanel.setBodyBorder(false);
//		rightpanel.setHeaderVisible(false);

		 peoplenum = new NumberField();
		peoplenum.setName("peoplenum");
		peoplenum.setAllowBlank(false);
		peoplenum.setFieldLabel("服务人数");

		
		 createdate = new DateField();
		createdate.setName("createdate");
		createdate.setAllowBlank(false);
		createdate.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-M-d H:mm:ss"));  
		createdate.setFieldLabel("建立日期");
		createdate.setVisible(false);
		
		
		servicestartdate = new DateField();
		servicestartdate.setName("servicestartdate");
		servicestartdate.setAllowBlank(false);
		servicestartdate.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-M-d H:mm:ss"));  
		servicestartdate.setFieldLabel("服务开始时间");
		
		serviceenddate = new DateField();
		serviceenddate.setVisible(false);
		serviceenddate.setName("serviceenddate");
	//	serviceenddate.setPropertyEditor(propertyEditor)
		//n.setPropertyEditorType(Integer.class);
		serviceenddate.setFormatValue(true);
		//serviceenddate.setAllowBlank(false);
		serviceenddate.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-M-d H:mm:ss"));  
		serviceenddate.setFieldLabel("服务结束时间");
		
		 roomno = new TextField<String>();
		roomno.setName("roomno");
	//	roomno.setAllowBlank(false);
		roomno.setFieldLabel("房间号");

		
		docname = new TextField<String>();
		docname.setName("docname");
		docname.setWidth(80);
		docname.setFieldLabel("单号");
		docname.setAllowBlank(false);
		
		pay = new NumberField();
		pay.setName("pay");
		pay.setWidth(80);
		pay.setFieldLabel("应收服务款");
		pay.setAllowBlank(true);
		 pay_g = new NumberField();
		 pay_g.setName("pay_g");
		 pay_g.setWidth(80);
		 pay_g.setFieldLabel("应收商品款");
		
		TextField<String> icode = new TextField<String>();
		icode.setName("icode");
		icode.setAllowBlank(false);
		icode.setEnabled(false);
		icode.setFieldLabel("编号");

//		ModelType type = new ModelType();
//		type.setRoot("records");
//		type.setRecordName("record");
//
//		type.addField("code");
//
//		type.addField("name");
//
//		StoreInfo info = new StoreInfo();
//
//		info.setTablename("ccode");
//		info.setSql("select ccode as code,cname as name from ccode");
//		BaseStore<BaseModelData> ccodestore = new BaseStore<BaseModelData>(
//				type, info);
//		ccode = new BaseComboBoxForm("code",
//				"name", ccodestore);
		ccode = new TextField<String>();
		ccode.setFieldLabel("客户");
		ccode.setName("ccode");
		ccode.setVisible(false);
		//ccode.setAllowBlank(false);
		
		
		 s_cardnothis = new TextField<String>();
		s_cardnothis.setName("s_cardno");
	//	roomno.setAllowBlank(false);
		s_cardnothis.setFieldLabel("会员卡号");
		
		
		cname_t = new TextField<String>();
		cname_t.setName("cname");
		// roomno.setAllowBlank(false);
		cname_t.setFieldLabel("会员名字");

		s_mobil = new TextField<String>();
		s_mobil.setName("s_mobil");
		// roomno.setAllowBlank(false);
		s_mobil.setFieldLabel("会员电话");
		// --------------
		// html = new NumberField();
		 html.setName("lastfiannce");
		// html.setAllowBlank(false);
		 html.setFieldLabel("余额");
		
		
		//zgw check_isas.setBoxLabel("使用会员卡");  
		
		//zgw check_isas.setName("check_isas");
		// --------------

//		leftpanel.add(icode);
//		rightpanel.add(ccode);
//		leftpanel.add(peoplenum);
//		rightpanel.add(roomno);
//		leftpanel.add(servicestartdate);
//		rightpanel.add(serviceenddate);
//
//		leftpanel.add(Accounts);
//		rightpanel.add(Paid);
		
		TableData bfp_td = new TableData();
		bfp_td.setColspan(1);
		bfp_td.setRowspan(1);
		// 对齐方式
		bfp_td.setHorizontalAlign(HorizontalAlignment.LEFT);
		bfp_td.setVerticalAlign(VerticalAlignment.TOP);
		bfp_td.setPadding(2);
		
		
		TableData bfp_td_set = new TableData();
		bfp_td_set.setColspan(4);
		bfp_td_set.setRowspan(1);
		// 对齐方式
		bfp_td_set.setHorizontalAlign(HorizontalAlignment.LEFT);
		bfp_td_set.setVerticalAlign(VerticalAlignment.TOP);
		bfp_td_set.setPadding(2);
		
		
		//bfp.add(new Label("使用会员卡:"),bfp_td);
		//----------------------------------------------start
		TableData td_isas = new TableData();
		td_isas.setColspan(1);
		td_isas.setRowspan(1);
		// 对齐方式
		td_isas.setHorizontalAlign(HorizontalAlignment.LEFT);
		td_isas.setVerticalAlign(VerticalAlignment.TOP);
		
		
		TableData td_isas2 = new TableData();
		td_isas2.setColspan(2);
		td_isas2.setRowspan(1);
		// 对齐方式
		td_isas2.setHorizontalAlign(HorizontalAlignment.RIGHT);
		td_isas2.setVerticalAlign(VerticalAlignment.TOP);

	/*	 fieldSet_isas = new FieldSet();  
		fieldSet_isas.setHeading("会员信息");  
	//	fieldSet_isas.setCheckboxToggle(true);  
		// zgw 2009-12-30 fieldSet_isas.setCollapsible(true);
		//fieldSet_isas.setExpanded(true);
		fieldSet_isas.setLayout(new TableLayout(5));
		
	  //  aslabel = new Label("会员卡号:");
	    fieldSet_isas.add(new Label("会员卡号:"),td_isas);
	    fieldSet_isas.add(s_cardnothis,td_isas);
	  //  fieldSet_isas.add( new Label("会员码:"), td_isas);
	  //  fieldSet_isas.add(ccode, td_isas); 
	    fieldSet_isas.add( new Label("会员名:"), td_isas);
	    fieldSet_isas.add(cname_t, td_isas); 
	     getassoc_button = new Button("获取会员信息");
	     getassoc_button.addListener(Events.Select, this);
	    fieldSet_isas.add(getassoc_button, td_isas); 
	    fieldSet_isas.add( new Label("电话:"), td_isas);
	    fieldSet_isas.add(s_mobil, td_isas); 
	    fieldSet_isas.add( new Label("会员卡余额:"), td_isas);
	    fieldSet_isas.add(html,td_isas);
	    html.setEnabled(false);
	    fieldSet_isas.add(ccode, td_isas); 
	    
	    
	    s_cardnothis.addListener(Events.KeyUp, this);
	    cname_t.addListener(Events.KeyUp, this);
	    s_mobil.addListener(Events.KeyUp, this);
	   
	    //----------------------------------------------end		
	//	bfp.add(check_isas,bfp_td_set);
	    bfp.add(fieldSet_isas,bfp_td_set);*/
	
		//bfp.add(html,bfp_td);
//		 aslabel = new Label("会员卡号:");
//		bfp.add(aslabel,bfp_td);
//		bfp.add(s_cardno,bfp_td);
		
		
		
//		bfp.add(new Label("客户名:"),bfp_td);
//		bfp.add(ccode,bfp_td);
/*		bfp.add(new Label("人数:"),bfp_td);
		bfp.add(peoplenum,bfp_td);
		bfp.add(new Label("房间号:"),bfp_td);
		bfp.add(roomno,bfp_td);*/
//		bfp.add(new Label("开始服务时间:"),bfp_td);
//		bfp.add(servicestartdate,bfp_td);
		//bfp.add(new Label("结束服务时间:"),bfp_td);
	
		bfp.add(new Label("单号:"),bfp_td);
		bfp.add(docname,bfp_td);
		
		bfp.add(new Label("应收服务款:"),bfp_td);
		bfp.add(pay,bfp_td);
		bfp.add(new Label("应收商品款:"),bfp_td);
		bfp.add(pay_g,bfp_td);
		
		bfp.add(serviceenddate,bfp_td);
		bfp.add(createdate,bfp_td);
		
		bfp.inited();
		/*
		 * leftpanel.add(codename); rightpanel.add(ccode);
		 * leftpanel.add(codename); rightpanel.add(ccode);
		 */

//		leftpanel.inited();
//		rightpanel.inited();
	
		
		TableData td = new TableData();
		td.setColspan(1);
		td.setRowspan(1);
		// 对齐方式
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);


		
//
	//	fieldSet.add(hpanel, td);

		final BorderLayout layout = new BorderLayout();
		service_panel.setHeaderVisible(false);
		service_panel.setLayout(layout);
		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
		centerData.setMargins(new Margins(5, 0, 5, 0));
		service_panel.add(bfp, centerData);
		// panel.setAutoHeight(true);
		service_panel.setHeight("50");
		service_panel.setWidth("600");
		//service_panel.setAutoWidth(true);
		//panel.setEnabled(false);
		//panel.mask("", "base-x-item-disabled");
		//加入事件侦听
		ccode.addListener(Events.Change, this);
		s_cardnothis.addListener(Events.Change, this);
		//zgw check_isas.addListener(Events.Change, this);
		cname_t.addListener(Events.Change, this);
		s_mobil.addListener(Events.Change, this);
		return service_panel;

	}

	/**
	 * 服务类型
	 * 
	 * @return
	 */
	BaseGrid createServiceItem() {
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

		
		/*List<ColumnConfig> bocodecolumns = new ArrayList<ColumnConfig>();
		ColumnConfig service = new ColumnConfig("service", "服务类型", 120);

		bocodecolumns.add(service);

		ColumnConfig price = new ColumnConfig("price", "单价", 100);
		price.setAlignment(HorizontalAlignment.RIGHT);
		price.setNumberFormat(NumberFormat.getCurrencyFormat());

		bocodecolumns.add(price);
		ColumnConfig priceunit = new ColumnConfig("priceunit", "单位", 50);

		bocodecolumns.add(priceunit);

		ModelType combotype = new ModelType();
		combotype.setRoot("records");
		combotype.setRecordName("record");
		combotype.setTotalName("totle");
		// combotype.addField("code", "service");
		combotype.addField("service");
		combotype.addField("priceunit");
		combotype.addField("price");
		combotype.addField("bcode");
		StoreInfo comboinfo = new StoreInfo();
		comboinfo.setTablename("s_service");
		comboinfo.setForcenolimit("yes");
		comboinfo.setSql("select service,priceunit,price from s_service");
		BaseGridEditor bge = new BaseGridEditor(bocodecolumns, combotype,
				comboinfo, "service");
		*/

		ColumnConfig serviceitem = new ColumnConfig("serviceitem", "服务类型", 80);
//		TextField<String> serviceitemtext = new TextField<String>();
//		GridEditor grideditor = new GridEditor(bge);
//		serviceitem.setEditor(serviceitemtext);
//		serviceitem.setRenderer(grideditor);
//		
//		grideditor.getField().setName("serviceitem");
//		grideditor.getField().addListener(Events.Change, this);

		
		

		ColumnConfig qty = new ColumnConfig("qty", "数量", 50);
		qty.setAlignment(HorizontalAlignment.RIGHT);
		//qty.setNumberFormat(NumberFormat.getFormat("#,##0"));
//		NumberField n = new NumberField();
//		n.setFormat(NumberFormat.getFormat("#,##0"));
//		n.setPropertyEditorType(Integer.class);
//		n.setName("qty");
//		n.addListener(Events.Change, this);
//		qty.setEditor(new CellEditor(n));
		//qty.getEditor().addListener(Events.Complete, this);
		
		ColumnConfig upric = new ColumnConfig("upric", "单价", 80);
		// TextField<String> uprictext = new TextField<String>();
		// upric.setEditor(new CellEditor(uprictext));
		upric.setAlignment(HorizontalAlignment.RIGHT);
//		upric.setNumberFormat(NumberFormat.getCurrencyFormat());
//		upric.setEditor(new CellEditor(new NumberField()));
//		upric.getEditor().getField().setName("upric");
//		upric.getEditor().getField().addListener(Events.Change, this);
		//upric.getEditor().addListener(Events.Complete, this);
	
		ColumnConfig qtyunit = new ColumnConfig("qtyunit", "单位", 50);
		
		ColumnConfig serviceitemtype = new ColumnConfig("serviceitemtype", "类型", 50);
//		TextField<String> qtyunittext = new TextField<String>();
//		qtyunit.setEditor(new CellEditor(qtyunittext));
		
		
		ColumnConfig total = new ColumnConfig("total", "小计", 80);
		// TextField<String> uprictext = new TextField<String>();
		// upric.setEditor(new CellEditor(uprictext));
		total.setAlignment(HorizontalAlignment.RIGHT);
		total.setNumberFormat(NumberFormat.getCurrencyFormat());
		//total.setEditor(new CellEditor(new NumberField()));
		
		
	
		
		 //**********************************
			
//		columns.add(bcode);
			//columns.add(c9);
			//columns.add(c10);
		//columns.add(method);
		columns.add(serviceitem);
		
		columns.add(qty);
		columns.add(upric);
		columns.add(qtyunit);
		columns.add(serviceitemtype);
		columns.add(total);
//		qtyunit.getEditor().addListener(Events.Complete, this);
//		upric.getEditor().addListener(Events.Complete, this);
//		
		
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");

		type.addField("idx");
		type.addField("icode");

		type.addField("serviceitem");

		type.addField("qty");

		type.addField("qtyunit");
		type.addField("upric");
		type.addField("bcode");
		type.addField("method");
		type.addField("total");
		type.addField("realtotal");
		type.addField("bcodeshortcode");
		type.addField("bname");
		
		type.addField("bcode801");
		type.addField("bcode802");
		type.addField("bcode810");
		type.addField("bcode800");
		type.addField("bcode900");
		
		type.addField("method801");
		type.addField("method802");
		type.addField("method810");
		type.addField("method800");
		type.addField("method900");
		type.addField("serviceitemtype");
		type.getField("qty").setType(Integer.class);
		type.getField("total").setType(Double.class);
		type.getField("upric").setType(Double.class);
		type.getField("bcode").setType(String.class);
		
		
		type.getField("realtotal").setType(Double.class);
		StoreInfo info = new StoreInfo();

		info.setTablename("s_service_po_g");
		info.setSql("select * from s_service_po_g where upicode='{icode}'");
		info.setParent(store);// 关联主表
		// info.setAutoinccolumn("idx"); // 自增字段，如果子表一定需要
		info.setLinkparentcolumns(new String[] { "icode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "upicode" });// 关联主表字段
																		// (子表)

		info.setKeyname(new String[] { "icode" }); // 主键

		s_service_po_g_store = new BaseStore<BusiObject>(type, info);
		s_service_po_g_store.setName("s_service_po_g");
		
		
		ColumnModel cm = new ColumnModel(columns);

		AggregationRowConfig averages = new AggregationRowConfig();
		averages.setHtml("serviceitem", "合计：");

		
		averages.setSummaryType("total", SummaryType.SUM);
		averages.setSummaryFormat("total", NumberFormat.getCurrencyFormat());
		
		 cm.addAggregationRow(averages);

//		bge.setTarget_store(s_service_po_g_store);
//		bge.setSourcecol(new ColumnInfo[] { new ColumnInfo("priceunit",ColumnInfo.STRING), new ColumnInfo("price",ColumnInfo.DOUBLE) });
//		bge.setTarget_col(new ColumnInfo[] { new ColumnInfo("qtyunit",ColumnInfo.STRING), new ColumnInfo("upric",ColumnInfo.DOUBLE) });
		//		
		 s_service_po_g_grid = new BaseGrid(s_service_po_g_store, cm)
		 {
			 public void deleterecord(){
				 super.deleterecord();
				 cal();
				 trysave();
				
			 }
		 };
		// s_service_po_g_grid.setEnabled(false);
		// s_service_po_g_grid.mask("sss", "base-x-item-disabled");
		// GroupSummaryView summary = new GroupSummaryView();
		cbs.setSelectionMode(SelectionMode.SINGLE);
		
		s_service_po_g_grid.setSelectionModel(cbs);
//		s_service_po_g_grid.setAutoHeight(true);

		//s_service_po_g_grid.setAutoWidth(true);
		s_service_po_g_grid.setWidth("600");
		s_service_po_g_grid.setHeight(150);
	
		s_service_po_g_grid.getView().setForceFit(true);
		registerStore(s_service_po_g_store);
		// bcgp = new
		// BaseChileGridPanel(type,info,columns,BaseChileGridPanel.QUERY_MODE);
		//s_service_po_g_store.addBaseStoreListener(BaseStoreEvent.EventType.CELL_CHANGED, this);
		s_service_po_g_grid.addListener(Events.AfterEdit, this );
		return s_service_po_g_grid;
	}
	//BaseFormPanel serviceitemform;
	@SuppressWarnings("unchecked")
	Widget  initserviceitemform()
	{
		BaseFormPanel serviceitemform = new BaseFormPanel(s_service_po_g_store);
		TableLayout tl = new TableLayout(4);
		tl.setWidth("600");
		TableData td = new TableData();
		td.setColspan(1);
		td.setRowspan(1);
	//	td.setWidth("50");
//		serviceitemform.setFieldWidth(100);
		// 对齐方式
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setPadding(2);
		
		
		serviceitemform.setLayout(tl);
		serviceitemform.setHeaderVisible(false);
		
		/* roomno = new TextField<String>();
			roomno.setName("roomno");
		
			roomno.setFieldLabel("房间号");*/
			

			FieldSet buttonset = new FieldSet();
			buttonset.setBorders(false);
			Button add = new Button("添加");
			
			Button del = new Button("删除");
			Button save = new Button("保存");
			Button paid = new Button("收银");
			Button EditComplete = new Button("结束本单据");
			buttonset.setLayout(new ColumnLayout());
			buttonset.add(add);
			buttonset.add(del);
			buttonset.add(save);
			buttonset.add(paid);
			buttonset.add(EditComplete);
			
			
//			EditComplete.setIconStyle("icon-complete");
//			EditComplete.setIconStyle("icon-complete");
//			save.setIconStyle("disk_black");
//			paid.setIconStyle("money_yen");
//			EditComplete.setIconStyle("icon-complete");
			
			save.setIcon(AbstractImagePrototype.create(BaseResource.INSTANCE.save2_16()));
			paid.setIcon(AbstractImagePrototype.create(BaseResource.INSTANCE.money_yen()));
			EditComplete.setIcon(AbstractImagePrototype.create(BaseResource.INSTANCE.icon_complete()));
			add.setIcon(AbstractImagePrototype.create(BaseResource.INSTANCE.addrecord()));
			del.setIcon(AbstractImagePrototype.create(BaseResource.INSTANCE.deleterecord()));
			
			final BaseComboBoxForm cc = CodeNameMapFactory.createfaxingshiInput_F();
			cc.setName("bcode800");
			
			
			BaseComboBoxForm<BaseModelData> dd = new BaseComboBoxForm(CodeNameMapFactory.loadBcode_801());
			BaseComboBoxForm<BaseModelData> ee = new BaseComboBoxForm(CodeNameMapFactory.loadBcode_802());
			
			//BaseComboBoxForm<BaseModelData> ee = new BaseComboBoxForm<BaseModelData>("bcode","bname","bcode","",false);
			
			BaseComboBoxForm<BaseModelData> ff = new BaseComboBoxForm(CodeNameMapFactory.loadBcode_810());
			BaseComboBoxForm<BaseModelData> gg = new BaseComboBoxForm(CodeNameMapFactory.loadBcode_900());

			final BaseComboBoxForm<BaseModelData> method800 = new BaseComboBoxForm(CodeNameMapFactory.getBaseMethodStore());
			method800.setName("method800");
			final BaseComboBoxForm<BaseModelData> method801 = new BaseComboBoxForm(CodeNameMapFactory.getBaseMethodStore());
			method801.setName("method801");
			final BaseComboBoxForm<BaseModelData> method802 = new BaseComboBoxForm(CodeNameMapFactory.getBaseMethodStore());
			method802.setName("method802");
			final BaseComboBoxForm<BaseModelData> method810 = new BaseComboBoxForm(CodeNameMapFactory.getBaseMethodStore());
			method810.setName("method810");
			final BaseComboBoxForm<BaseModelData> method900 = new BaseComboBoxForm(CodeNameMapFactory.getBaseMethodStore());
			method900.setName("method900");
			
			dd.setName("bcode801");
			ee.setName("bcode802");
			ff.setName("bcode810");
			gg.setName("bcode900");
			
			
			 service_qty= new NumberField();
			service_qty.setName("qty");
			//service_qty.setFormat(NumberFormat.getFormat("#,##0"));
			service_qty.setAllowBlank(false);
			service_qty.setPropertyEditorType(Integer.class);
			
			service_upric = new NumberField();
			service_upric.setName("upric");
		//	service_upric.setFormat(NumberFormat.getFormat("#,##0"));
			service_upric.setAllowBlank(false);
			
			final TextField<String> service_qtyunit  = new TextField<String>();
			service_qtyunit.setName("qtyunit");
			service_qtyunit.setAllowBlank(false);
			
			 service_total = new NumberField();
			service_total.setName("total");
		//	service_total.setFormat(NumberFormat.getFormat("#,##0"));
			service_total.setAllowBlank(false);
			service_total.setEnabled(false);
			 service_realtotal = new NumberField();
			service_realtotal.setName("realtotal");
		//	service_realtotal.setFormat(NumberFormat.getFormat("#,##0"));
			service_realtotal.setAllowBlank(false);
			
			
//			buttonset.add(new Label("服务类型:"));
//			buttonset.add(bge2);
			
			serviceitemform.add(buttonset,td);
//			serviceitemform.add(del,td);
//			serviceitemform.add(save,td);
		
			serviceitemform.add(new Label("总监:"),td);
			serviceitemform.add(cc,td);
		
		    serviceitemform.add(method800,td);

		    
		    
		    //服务类型
			//---------------------
			List<ColumnConfig> bocodecolumns = new ArrayList<ColumnConfig>();
			ColumnConfig service = new ColumnConfig("service", "服务类型", 120);

			bocodecolumns.add(service);

			ColumnConfig price = new ColumnConfig("price", "单价", 100);
			price.setAlignment(HorizontalAlignment.RIGHT);
			price.setNumberFormat(NumberFormat.getCurrencyFormat());

			bocodecolumns.add(price);
			ColumnConfig priceunit = new ColumnConfig("priceunit", "单位", 50);
			bocodecolumns.add(priceunit);
			
			ColumnConfig type = new ColumnConfig("type", "类型", 50);
			bocodecolumns.add(type);
			
			ModelType combotype = new ModelType();
			combotype.setRoot("records");
			combotype.setRecordName("record");
			combotype.setTotalName("totle");
			// combotype.addField("code", "service");
			combotype.addField("service");
			combotype.addField("priceunit");
			combotype.addField("price");
			combotype.addField("bcode");
			combotype.addField("type");
			StoreInfo comboinfo = new StoreInfo();
			comboinfo.setTablename("s_service");
			comboinfo.setForcenolimit("true");
			//comboinfo.setNeedAllRow("true");
			comboinfo.setSql("select service,priceunit,price,type from s_service");
			 bgeserviceitem = new BaseGridEditor(bocodecolumns, combotype,
					comboinfo, "service"){
			
				public void doposted( ModelData modeldata) {
					service_qtyunit.setFireChangeEventOnSetValue(true);
					service_upric.setFireChangeEventOnSetValue(true);
					
					service_qtyunit.setValue(""+modeldata.get("priceunit"));
//					service_qtyunit.setValue("ee");
				
					service_upric.setValue(Double.parseDouble(""+modeldata.get("price")));
					service_qtyunit.setFireChangeEventOnSetValue(false);
					service_upric.setFireChangeEventOnSetValue(false);
					//设置类型
					s_service_po_g_store.setValue("serviceitemtype", modeldata.get("type"));
				}
			};
			
			//------------------------------
			
			bgeserviceitem.setName("serviceitem");

			
		    //-------------
			FieldSet fs = new FieldSet();
			TableLayout fs_tl = new TableLayout(2);
			
			TableData fs_td = new TableData();
			fs_td.setColspan(1);
			fs_td.setRowspan(1);
			fs.setLayout(fs_tl);
			fs.add(new Label("服务类型:"),fs_td);
			fs.add(bgeserviceitem,fs_td);
			fs.add(new Label("数量:"),fs_td);
			fs.add(service_qty,fs_td);
			fs.add(new Label("单价:"),fs_td);
			fs.add(service_upric,fs_td);
			fs.add(new Label("单位:"),fs_td);
			fs.add(service_qtyunit,fs_td);
			
			fs.add(new Label("应收:"),fs_td);
			fs.add(service_total,fs_td);
			
			fs.add(new Label("实收:"),fs_td);
			fs.add(service_realtotal,fs_td);
			
			TableData fs_td2 = new TableData();
			fs_td2.setHorizontalAlign(HorizontalAlignment.LEFT);
			fs_td2.setVerticalAlign(VerticalAlignment.TOP);
			fs_td2.setColspan(1);
			fs_td2.setRowspan(5);
			   serviceitemform.add(fs,fs_td2);
		    //-----------------
		    
		    
			   
	
			
			serviceitemform.add(new Label("发型师:"),td);
			
			serviceitemform.add(dd,td);
			serviceitemform.add(method801,td);
		
			    
			    
			serviceitemform.add(new Label("A技师:"),td);
			serviceitemform.add(ee,td);
			serviceitemform.add(method802,td);

			serviceitemform.add(new Label("B技师:"),td);
			serviceitemform.add(ff,td);
			serviceitemform.add(method810,td);
			serviceitemform.add(new Label("助理:"),td);
			serviceitemform.add(gg,td);
			serviceitemform.add(method900,td);
		
			add.addSelectionListener(new SelectionListener<ButtonEvent>(){

				@Override
				public void componentSelected(ButtonEvent ce) {
					s_service_po_g_grid.addnewrecord();
					}
				
			});
			del.addSelectionListener(new SelectionListener<ButtonEvent>(){

				@Override
				public void componentSelected(ButtonEvent ce) {
					s_service_po_g_grid.deleterecord();
					//s_service_po_g_grid.getStore().setValue("upric", 100);
					}
				
			});
			save.addSelectionListener(new SelectionListener<ButtonEvent>(){

				@Override
				public void componentSelected(ButtonEvent ce) {
					//s_service_po_g_grid.getStore().trySave();
					int count =basegrid.getStore().indexOf(basegrid.getSelectionModel().getSelectedItem());
					basegrid.getStore().trySave(count);
					}
				
			});
			paid.addSelectionListener(new SelectionListener<ButtonEvent>(){

				@Override
				public void componentSelected(ButtonEvent ce) {
					
					
					paidX();
					
				}
				
			});
			//结束此单据
			EditComplete.addSelectionListener(new SelectionListener<ButtonEvent>(){

				@Override
				public void componentSelected(ButtonEvent ce) {
					
					
					enitcomplete();
				}
				
			});
			
			service_qty.addListener(Events.Change, this);
			service_upric.addListener(Events.Change, this);
			bgeserviceitem.addListener(Events.Change, this);
			service_realtotal.addListener(Events.Change, this);
			serviceitemform.inited();
			VerticalPanel vpanel = new VerticalPanel();
			vpanel.add(buttonset);
			
		
			
			vpanel.add(serviceitemform);
			vpanel.setSpacing(0);
			
			return vpanel;
	}
	/**
	 * 结束单据
	 */
	protected void enitcomplete() {

		if(!cal())
		{
			MessageBox.alert("禁止", "金额合计数录入不正确！请检查子项目的合计金额", null);
			return ;
		}
		String str = canbepaid();
		 if(store.getValue("busistatus").equals("524288"))
		{
			MessageBox.alert("禁止", "你已经进行过此操作，如果单据录入错误，请先“修改此单据”", null);
		}
		 else if(str.length()>0)
		 {
			 MessageBox.alert("警告", str, null);  
		 }
		 else if(!store.getValue("busistatus").equals("131072"))
		 {
			 MessageBox.alert("禁止", "请先进行“收银”", null);
		 }
		 else 
		 {
			 //store.setValue("busistatus", "524288");
			 setAllEditAble(false);
		Date d = new Date();
		serviceenddate
				.setFireChangeEventOnSetValue(true);
		serviceenddate.setValue(d);
		int count =basegrid.getStore().indexOf(basegrid.getSelectionModel().getSelectedItem());
		basegrid.getStore().trySave(count);
		
		 }
		
		
	}

	private BaseGridEditor bb()
	{
		//
		List<ColumnConfig> bocodecolumns = new ArrayList<ColumnConfig>();
		ColumnConfig service = new ColumnConfig("service", "服务", 120);

		bocodecolumns.add(service);

		ColumnConfig price = new ColumnConfig("price", "单价", 100);
		price.setAlignment(HorizontalAlignment.RIGHT);
		price.setNumberFormat(NumberFormat.getCurrencyFormat());

		bocodecolumns.add(price);
		ColumnConfig priceunit = new ColumnConfig("priceunit", "单位", 50);

		bocodecolumns.add(priceunit);

		ModelType combotype = new ModelType();
		combotype.setRoot("records");
		combotype.setRecordName("record");
		combotype.setTotalName("totle");
		// combotype.addField("code", "service");
		combotype.addField("service");
		combotype.addField("priceunit");
		combotype.addField("price");
		combotype.addField("bcode");
		StoreInfo comboinfo = new StoreInfo();
		comboinfo.setTablename("s_service");
		comboinfo.setSql("select service,priceunit,price from s_service");
		BaseGridEditor bge = new BaseGridEditor(bocodecolumns, combotype,
				comboinfo, "service");
		
		return bge;
	}

	
void initListener()
{
	StoreListener<ModelData> listener = new StoreListener<ModelData>() {
		 public void storeDataChanged(StoreEvent<ModelData> se) {
		       // onDataChanged(se);
		      }
	 };
}
 int sync = 0;
	/* (non-Javadoc)
	 * @see com.extjs.gxt.ui.client.event.Listener#handleEvent(com.extjs.gxt.ui.client.event.BaseEvent)
	 */
	public void handleEvent(BaseEvent be) {
		
		sync++;
		try {
			if (sync == 1) {

				
				Debug.printf(be.getType(), 4);
				if (be.getType() == Events.Select) {
					if (be.getSource() == startbutton) {
						Date d = new Date();
						/*
						 * DateTimeFormat activeFormat =
						 * DateTimeFormat.getFormat("yyyy-M-d h:mm:ss"); String
						 * formattedValue = activeFormat.format(d);
						 */
						servicestartdate.setFireChangeEventOnSetValue(true);
						servicestartdate.setValue(d);
						// servicestartdate.setRawValue(formattedValue);
					} else if (be.getSource() == endbutton) {
						enitcomplete();
					} else if (be.getSource() == paidbutton) {
						
						paidX();
					}
					else if (be.getSource() == printer) {
						
//						store.setValue("busistatus", "128");
//						store.setValue("busistatus", "131072");
						Object status = store.getValue("busistatus");
						if(status!=null && (status.equals("131072") ||status.equals("524288")))
						{
						Print() ;
						}
						else
						{
							MessageBox.alert("警告", "必须先进行“收银”才能进行“打印”。\n“收银”按钮在工具栏。", null);
						}
					}
					else if (be.getSource() == addnew) {
						
						basegrid.addnewrecord();
					}
					
					else if (be.getSource() == getassoc_button) {
						if(!(s_cardnothis.getValue()==null || s_cardnothis.getValue().equals("")) )
						{
						final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
						.create(com.base.myproject.client.tools.GreetingService.class);
						greetingService.getAssociator(s_cardnothis.getValue(),4,this);
						}
						else if(!(cname_t.getValue()==null || cname_t.getValue().equals("")) )
						{
						final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
						.create(com.base.myproject.client.tools.GreetingService.class);
						greetingService.getAssociator(cname_t.getValue(),2,this);
						}
						else if(!(s_mobil.getValue()==null || s_mobil.getValue().equals("")) )
						{
						final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
						.create(com.base.myproject.client.tools.GreetingService.class);
						greetingService.getAssociator(s_mobil.getValue(),3,this);
						}
					}
					else if (be.getSource() == associatorbutton) {
						AssociatorPanel associatorpanel = new AssociatorPanel();
						associatorpanel.getDialog().show();
					}
					else if (be.getSource() == changedpo) {
						
						BcodeChecker b = new BcodeChecker(){
//							Button  aaa = new Button("修改重新收钱");
//							Button  bbb = new Button("修改至可以修改技师资料");
							public void showDialog()
							{
								d.setWidth("100");
								CodeNameMapFactory cnmf = new CodeNameMapFactory();
								
								List<ColumnConfig> bocodecolumns2 = new ArrayList<ColumnConfig>();
								ColumnConfig bcode2 = new ColumnConfig("code", "人员", 100);

								bocodecolumns2.add(bcode2);

								ColumnConfig bname = new ColumnConfig("name", "人员名", 100);
								bocodecolumns2.add(bname);
								bge2 = new BaseGridEditor(bocodecolumns2, cnmf
										.getBasebcodestore_canChangePO(), "name", "code");
								//final TextField<String> bge2 = new TextField<String>();
								bge2.setFieldLabel("操作员");
								bge2.setAllowBlank(false);
								 //----
								
								pass_t.setAllowBlank(false);
								pass_t.setFieldLabel("密码");
								pass_t.setPassword(true);
								
								formpanel.setLabelWidth(75);
								formpanel.setFieldWidth(120);
								formpanel.add(bge2);
								formpanel.add(pass_t);
								
//								formpanel.add(aaa);
//								formpanel.add(bbb);
//								aaa.setEnabled(false);
//								bbb.setEnabled(false);
								d.setSize(260, 400);
								d.add(formpanel);
								d.setButtons(Dialog.OKCANCEL);
								d.getButtonById(Dialog.CANCEL).addListener(Events.Select, this);
								d.getButtonById(Dialog.OK).addListener(Events.Select, this);
								d.show();
							}
							public void handleEvent(BaseEvent be) {
								
								  if(be.getSource() == d.getButtonById(Dialog.CANCEL))
									{
										d.setVisible(false);
									}
									else if(be.getSource() == d.getButtonById(Dialog.OK))
									{
										if(formpanel.isValid())
										{
										checkbcode();
									
										}
									}
							}
							
							@Override
							public void onFailure(Throwable caught) {
								
							}

							@Override
							public void onSuccess(Boolean result) {
								
								
								if(result)
								{
//									aaa.setEnabled(true);
//									bbb.setEnabled(true);
									store.setValue("busistatus", "128");
									//vpanel.unmask();
									setDisableed(false);
									setAllEditAble(true);
								}
								else
								{
									Info.display("","密码不正确!!");
									
								}
							}
							
						};
				
						b.showDialog();
					
						
					}
					
					else if (be.getSource() == addfinance) {
						//bug
						AddFinace addfinace = new AddFinace()
						{
							public void addfinancesuccess(Element elem ) {
								super.addfinancesuccess(elem);
								if(check_isas.getValue()!=null && check_isas.getValue() && s_cardno.getValue()!=null)
								{
								final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
								.create(com.base.myproject.client.tools.GreetingService.class);
								greetingService.getAssociator(s_cardno.getValue(),4,new AsyncCallback<Associator> (){

									@Override
									public void onFailure(Throwable caught) {
										// TODO Auto-generated method stub
										
									}

									@Override
									public void onSuccess(Associator result) {
									//	if(associator.getS_cardno().equals(result.getS_cardno()))
										GWT.log("---"+s_cardnothis.getValue(), null);
										GWT.log("==="+result.getS_cardno(), null);
										System.out.println("---"+s_cardnothis.getValue());
										System.out.println("==="+result.getS_cardno());
										if(s_cardnothis.getValue().equals(result.getS_cardno()))
										getAssociatorSuccess(result);
									}
									
								});
								}
							}
						};
						addfinace.showDialog();
						
//						new AddFinace().showDialog();
					}
					//交接
					else if (be.getSource() == associate) {
						printer();
					}
					else if(be.getSource().equals(newccode))
					{
						 NewCCode newccode = new NewCCode();
						 newccode.show();
					}
					
				} else if (be.getType() == Events.Change) {
					Debug.printf("changed!!", 4);
					// String name = (be.getSource()).getField().getName();
					Debug.printf("changed!!"
							+ ((FieldEvent) be).getField().getName(), 4);
					String name = ((FieldEvent) be).getField().getName();
					
					 if (name.equals("bcodeshortcode")) {}
					
					// 录入卡号
					else if (name.equals("s_cardno")) {
						Debug.printf("s_cardno input ", 4);

						be.setCancelled(true);
						final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
						.create(com.base.myproject.client.tools.GreetingService.class);
						greetingService.getAssociator(s_cardnothis.getValue(),4,this);

					} 
					
					
					
					else if(be.getSource().equals(bgeserviceitem) || be.getSource().equals(service_qty) || be.getSource().equals(service_upric))
					{
						//Window.alert("44");
						double qty = Double.parseDouble(service_qty.getValue() == null ? "0"
								: service_qty.getValue().toString());
						double upric = Double.parseDouble(service_upric.getValue() == null ? "0"
								: service_upric.getValue().toString());
						service_total.setFireChangeEventOnSetValue(true);
						service_realtotal.setFireChangeEventOnSetValue(true);
						service_total.setValue(upric * qty);
						service_realtotal.setValue(upric * qty);
						service_total.setFireChangeEventOnSetValue(false);
						service_realtotal.setFireChangeEventOnSetValue(false);
						cal();
						//Window.alert(""+(upric * qty));
					}

				} else if (be.getType() == Events.Complete) {
					/*
					 * Debug.printf("resource=="+((Editor)be.getSource()).getTitle
					 * (), 4);
					 * Debug.printf("Editor value=="+((Editor)be.getSource
					 * ()).getValue(), 4);
					 * Debug.printf("Editor getName=="+((Editor
					 * )be.getSource()).getField().getName(), 4);
					 * Debug.printf(s_service_po_g_store.getValue("qty"), 4);
					 */
					// com.extjs.gxt.samples.resources.client.model.Stock;
					// String name =
					// ((Editor)be.getSource()).getField().getName();
					// if (name.equals("qty")||name.equals("upric"))
					{
						// int index = s_service_po_g_store.getCurcowindex();
						/*
						 * if (index != -1) { double qty =
						 * Double.parseDouble(s_service_po_g_store
						 * .getValue(index, "qty") == null ? "0" :
						 * s_service_po_g_store.getValue(index, "qty")
						 * .toString()); double price =
						 * Double.parseDouble(s_service_po_g_store
						 * .getValue(index, "upric") == null ? "0" :
						 * s_service_po_g_store.getValue(index, "upric")
						 * .toString()); // total Debug.printf("qty =" + qty,
						 * 4); Debug.printf("price = " + price, 4);
						 * s_service_po_g_store.setValue(index, "total", qty *
						 * price); }
						 */
					}
				}
				else if (be.getType() == Events.KeyUp) {
					Debug.printf("keyup" +be.getClass());
					Debug.printf("keyup" +be.getType());
					if(be instanceof ComponentEvent)
					{
						Debug.printf("keyup" +((ComponentEvent) be).getKeyCode());
						if(((ComponentEvent) be).getKeyCode()==9)
						{
							
						}
					
						else if(be.getSource().equals(s_cardnothis))
					{
						
							ccode.setFireChangeEventOnSetValue(true);
							cname_t.setFireChangeEventOnSetValue(true);
							s_mobil.setFireChangeEventOnSetValue(true);
							//s_cardnothis.setFireChangeEventOnSetValue(true);
							html.setFireChangeEventOnSetValue(true);
							//s_cardnothis.setValue("");
							ccode.setValue("");
							html.setValue(0);
							
							
							cname_t.setValue("");
							s_mobil.setValue("");
							
							//s_cardnothis.setFireChangeEventOnSetValue(false);
							ccode.setFireChangeEventOnSetValue(false);
							cname_t.setFireChangeEventOnSetValue(false);
							s_mobil.setFireChangeEventOnSetValue(false);
							html.setFireChangeEventOnSetValue(false);
					}
					else if(be.getSource().equals(s_mobil))
					{
						s_cardnothis.setValue("");
						cname_t.setValue("");
						html.setValue(0);
					}
					else if(be.getSource().equals(cname_t))
					{
						s_mobil.setValue("");
						s_cardnothis.setValue("");
						html.setValue(0);
					}
					}
				}
				else if (be.getType() == Events.AfterEdit) {
					
					final GridEvent<BusiObject> be2 = (GridEvent<BusiObject>)be;
					//((BaseGrid<BusiObject>)be2.getGrid()).setValue(be2.getRowIndex(), "bname", "sss");
					

					
					
					if (be2.getProperty().equals("bcodeshortcode")) {
						final int index = be2.getRowIndex();
						Debug.printf("index = " + index);
						if (index != -1) {

							// Object shortcode = ((FieldEvent)
							// be).getField().getValue();
							Object shortcode = be2.getValue();
							if (shortcode != null) {
								String shortcodestr = shortcode.toString();
								final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
										.create(com.base.myproject.client.tools.GreetingService.class);
							//	greetingService.getbnamebyshortname(shortcodestr, new AsyncCallback<String>() {
								greetingService.getBcode("bcodeshortcode",shortcodestr, new AsyncCallback<BcodeSync>() {
								
									@Override
									public void onFailure(Throwable caught) {

									}

									@Override
									public void onSuccess(BcodeSync result) {
										if (result != null) {
											Debug.printf("index2 = " + result.getBname()+""+result.getBcodeshortcode());
//											s_service_po_g_store.setValue(index,
//													"bcode", result[0]);
//											s_service_po_g_store.setValue(index,
//													"bname", result[1]);
											
									//		((BaseGrid<BusiObject>)be2.getGrid()).setValue(be2.getRowIndex(), "bcode", result[0]);
											((BaseGrid<BusiObject>)be2.getGrid()).setValue(be2.getRowIndex(), "bname", result.getBname());
											
										}
									}

								});
							}
						}
					
				}
					else if (be2.getProperty().equals("qty") || be2.getProperty().equals("upric") ||be2.getProperty().equals("serviceitem")) {

						final int index = be2.getRowIndex();
						if (index != -1) {
							double qty = Double.parseDouble(((BaseGrid<BusiObject>)be2.getGrid()).getValue(index, "qty") == null ? "0"
									: ((BaseGrid<BusiObject>)be2.getGrid()).getValue(index, "qty").toString());
							
							double price = Double
									.parseDouble(((BaseGrid<BusiObject>)be2.getGrid()).getValue(index, "upric") == null ? "0"
											: ((BaseGrid<BusiObject>)be2.getGrid()).getValue(index, "upric").toString());
							// total

							((BaseGrid<BusiObject>)be2.getGrid()).setValue(index, "total", qty
									* price);

							cal();
						}

					
					}
				
//						else if (be2.getProperty().equals("upric")) {
//							final int index = be2.getRowIndex();
//							if (index != -1) {
//								double upric = Double.parseDouble(((FieldEvent) be)
//										.getField().getValue() == null ? "0"
//										: ((FieldEvent) be).getField().getValue()
//												.toString());
//								double qty = Double
//										.parseDouble(s_service_po_g_store.getValue(
//												index, "qty") == null ? "0"
//												: s_service_po_g_store.getValue(
//														index, "qty").toString());
//								// total
//
//								s_service_po_g_store.setValue(index, "total", qty
//										* upric);
//							}
//					}
					
				}
				
			}
			}
		
			finally {
			sync--;
			Debug.printf("suync="+sync, 4);
		}
		
	}

	private boolean  cal() {
		double d_pay = 0.00;
		double d_pay_g = 0.00;
		for (int i = 0; i < s_service_po_g_store.getCount(); i++) {
			if((s_service_po_g_store.getAt(i).getBusistatus() & BusiObject.DELETE)!=BusiObject.DELETE)
			{
				if(s_service_po_g_store.getValue(i, "serviceitemtype")==null)
						{
						continue;
						}
				if(s_service_po_g_store.getValue(i, "serviceitemtype").equals("商品"))
				{
					
					
					Object  o =s_service_po_g_store.getValue(i, "total");
					d_pay_g += Double.parseDouble(o==null?"0":o.toString());
				}
				else
				{
					Object o = s_service_po_g_store
					.getValue(i, "total").toString();
					d_pay += Double.parseDouble(o==null?"0":o.toString());
				}
			}
		}
		//只有在准备状态的时候才能进行资金的汇总
		if(store.getValue("busistatus").equals("128"))
		{
			pay.setFireChangeEventOnSetValue(true);
			pay.setValue(d_pay);
			pay_g.setFireChangeEventOnSetValue(true);
			pay_g.setValue(d_pay_g);
		}
		double  totle = d_pay+d_pay_g;
		Object d_payvalue = pay.getValue();
		Object d_pay_gvalue = pay_g.getValue();
		double d_payvaluedouble = Double.parseDouble(d_payvalue==null?"0":d_payvalue.toString());
		double d_pay_gvaluedouble = Double.parseDouble(d_pay_gvalue==null?"0":d_pay_gvalue.toString());
		
		if(d_payvaluedouble+d_pay_gvaluedouble -totle >0.01 || d_payvaluedouble+d_pay_gvaluedouble -totle<-0.01)
		
		{
			return false;
		}
		return true;
		
		//默认不自动录入数据，要手工录入
//		Paid.setFireChangeEventOnSetValue(true);
//		Paid.setValue(d);
		
	}
	
	public void paided()
	{
		store.setValue("busistatus", "131072");
		Date d = new Date();
		serviceenddate
				.setFireChangeEventOnSetValue(true);
		serviceenddate.setValue(d);
		store.trySave();
		 setDisableed(true);
	}

	void updateassociator(Associator result)
	{
		
		//this.associator = result;
		s_cardnothis.setValue(result.getS_cardno());
		
		ccode.setValue(result.getCcode());
		cname_t.setValue(result.getName());
		s_mobil.setValue(result.getPhone());
		html.setValue(result.getFinance());
	}
	@Override
	public void BaseStoreEventHandle(BaseStoreEvent evt) {
		Debug.printf("icode="+evt.getBasestore().getValue("icode"),4);
		Debug.printf("evt.getEventType()"+evt.getEventType());
		Object status = evt.getBasestore().getValue("busistatus");
		if(evt.getEventType()==BaseStoreEvent.EventType.ROW_CHANGED)
		{
		
			if (status != null && status.equals("131072")) {
				setDisableed(true);
				vpanel.unmask();
				
			}
			else if(status != null && status.equals("524288")) {
				
				setAllEditAble(false);
			}
			else {
				setDisableed(false);
				setAllEditAble(true);
			}
		}
		else if(evt.getEventType()==BaseStoreEvent.EventType.CELL_CHANGED)
		{}
	}
/**
 * 
 * @param b true 不可以编辑，false可以编辑
 */
	void setDisableed(boolean b)
	{
		if(b)
		{
			
			bfp.setEnabled(!b);
//			 vpanel.mask(null,"base-ext-el-mask");
			 changedpo.setEnabled(true);
		}
		else
		{
			
			bfp.setEnabled(!b);
			// vpanel.unmask();
			 changedpo.setEnabled(false);
		}
	}
	/**
	 * 设置Vpanel可以编辑，状态回归原始状态
	 * @param b true 可以编辑，false不可以编辑
	 */
	void setAllEditAble(boolean b)
	{
		if(!b)
		{
			store.setValue("busistatus", "524288");
			vpanel.mask(null,"base-ext-el-mask");
			changedpo.setEnabled(true);
		}
		else
		{
			store.setValue("busistatus", "128");
			vpanel.unmask();
			changedpo.setEnabled(false);
		}
	}
	
	@Override
	public void onFailure(Throwable caught) {
		
		Debug.printf("error");
	}

	@Override
	public void onSuccess(Associator result) {
		getAssociatorSuccess(result);
	}
	private void  getAssociatorSuccess(Associator result)
			{
		try
		{
			sync++;
		if(result.getName()!=null)
		{
//		ccode.setSimpleValue(result.getCcode());
		ccode.setFireChangeEventOnSetValue(true);
		cname_t.setFireChangeEventOnSetValue(true);
		s_mobil.setFireChangeEventOnSetValue(true);
		s_cardnothis.setFireChangeEventOnSetValue(true);
		html.setFireChangeEventOnSetValue(true);
		updateassociator(result);

		s_cardnothis.setFireChangeEventOnSetValue(false);
		ccode.setFireChangeEventOnSetValue(false);
		cname_t.setFireChangeEventOnSetValue(false);
		s_mobil.setFireChangeEventOnSetValue(false);
		html.setFireChangeEventOnSetValue(false);
		//html.setHtml("可用余额："+result.getFinance());
		
		// associator = result;
		}
		else{
//			ccode.setFireChangeEventOnSetValue(true);
//			cname_t.setFireChangeEventOnSetValue(true);
//			s_mobil.setFireChangeEventOnSetValue(true);
//			s_cardnothis.setFireChangeEventOnSetValue(true);
//			html.setFireChangeEventOnSetValue(true);
			reset();
			
			//html.setValue(0);
			
//			s_cardnothis.setFireChangeEventOnSetValue(false);
//			ccode.setFireChangeEventOnSetValue(false);
//			cname_t.setFireChangeEventOnSetValue(false);
//			s_mobil.setFireChangeEventOnSetValue(false);
//			html.setFireChangeEventOnSetValue(false);
			Info.display("错误", "没要找到会员信息！");
		}
		}
		finally {
			sync--;
			Debug.printf("suync2="+sync, 4);
		}
			}
	private void reset()
	{
		ccode.setFireChangeEventOnSetValue(true);
		cname_t.setFireChangeEventOnSetValue(true);
		s_mobil.setFireChangeEventOnSetValue(true);
		s_cardnothis.setFireChangeEventOnSetValue(true);
		html.setFireChangeEventOnSetValue(true);
		s_cardnothis.setValue("");
		ccode.setValue("");
		html.setValue(0);
		
		
		cname_t.setValue("");
		s_mobil.setValue("");
		
		s_cardnothis.setFireChangeEventOnSetValue(false);
		ccode.setFireChangeEventOnSetValue(false);
		cname_t.setFireChangeEventOnSetValue(false);
		s_mobil.setFireChangeEventOnSetValue(false);
		html.setFireChangeEventOnSetValue(false);
	}
	
	/*
	 * 	type.addField("serviceitem");

		type.addField("qty");

		type.addField("qtyunit");
		type.addField("upric");
		type.addField("bcode");
		type.addField("method");
		type.addField("total");
		type.addField("realtotal");
		type.addField("bcodeshortcode");
		type.addField("bname");
		
		type.addField("bcode801");
		type.addField("bcode802");
		type.addField("bcode810");
		type.addField("bcode800");
		type.addField("bcode900");
		
		type.addField("method801");
		type.addField("method802");
		type.addField("method810");
		type.addField("method800");
		type.addField("method900");
		type.getField("qty").setType(Integer.class);
		type.getField("total").setType(Double.class);
		type.getField("upric").setType(Double.class);
		type.getField("bcode").setType(String.class);
	 */
	//检查必录
	String canbepaid()
	{
		int rownum = 1;
		StringBuffer sbf = new StringBuffer();

		if(s_service_po_g_store.getCount()==0)
		{
			sbf.append("服务类型等为空（无服务记录） \n");
		}
		for(BusiObject bo:s_service_po_g_store.getModels())
		{
			StringBuffer sbftemp = new StringBuffer();
//			if(bo.get("qty")==null || bo.get("qty").equals(""))
//				return false;
			if(bo.get("serviceitem")==null)
				sbftemp.append("服务类型未录入 \n");
			if(bo.get("qty")==null)
				sbftemp.append("数量未录入 \n");
			if(bo.get("qtyunit")==null)
				sbftemp.append("单位未录入 \n");
			if(bo.get("upric")==null)
				sbftemp.append("单价未录入 \n");
			if(bo.get("realtotal")==null)
				sbftemp.append("实收未录入 \n");
			   //总监   发型师 A技师B技师助理
			if((bo.get("bcode800")!=null ) || (bo.get("method800")!=null ))
			{
				if((bo.get("bcode800")==null ) || (bo.get("method800")==null ))
				sbftemp.append("总监和指定类型必须同时录入或同时不录 \n");
			}
			if((bo.get("bcode801")!=null ) || (bo.get("method801")!=null ))
			{
				if((bo.get("bcode801")==null ) || (bo.get("method801")==null ))
				sbftemp.append("发型师 和指定类型必须同时录入或同时不录 \n");
			}
			if((bo.get("bcode802")!=null ) || (bo.get("method802")!=null ))
			{
				if((bo.get("bcode802")==null ) || (bo.get("method802")==null ))
				sbftemp.append("A技师和指定类型必须同时录入或同时不录 \n");
			}
			if((bo.get("bcode810")!=null ) || (bo.get("method810")!=null ))
			{
				if((bo.get("bcode810")==null ) || (bo.get("method810")==null ))
				sbftemp.append("B技师和指定类型必须同时录入或同时不录 \n");
			}
			if((bo.get("bcode900")!=null ) || (bo.get("method900")!=null ))
			{
				if((bo.get("bcode900")==null ) || (bo.get("method900")==null ))
				sbftemp.append("助理和指定类型必须同时录入或同时不录 \n");
			}

			if ((bo.get("bcode800") == null) && (bo.get("bcode801") == null)
					&& (bo.get("bcode802") == null)
					&& (bo.get("bcode810") == null)
					&& bo.get("bcode900") == null
					&& bo.get("method800") == null
					&& bo.get("method801") == null
					&& bo.get("method802") == null
					&& bo.get("method810") == null
					&& (bo.get("method900") == null)) {
				
				sbftemp.append("总监  , 发型师, A技师,B技师,助理不能同时为空 \n");
			}
			
			
			if(sbftemp.length()>0)
			{
				sbf.append("第" +rownum+"行\n");
				sbf.append(sbftemp);
			}
			rownum++;
		}
		return sbf.toString();
	}
	/**
	 * 对话框方式
	 */
	public void paidX()
	{

		
		
		//保证  “实收款” 先录入，2010-05-27修改，
	/*		if(Paid.getValue()==null || Paid.getValue().doubleValue()<1)
			{
				
				MessageBox.alert("禁止", "请先录入 “实收款”金额。", null);
				
			}*/
			if((pay.getValue()==null || pay.getValue().doubleValue()<1) && (pay_g.getValue()==null || pay_g.getValue().doubleValue()<1))
			{
				
				MessageBox.alert("禁止", "根据实际情况，应收服务与商品款必须录入一项。", null);
				
			}
			
			else if(!store.getValue("busistatus").equals("128"))
			{
				MessageBox.alert("禁止", "你已经进行过此操作，如果单据录入错误，请先“修改此单据”", null);
			}
			else
			{
			 PaidDialog pd = new PaidDialog(){
				 
				 public void payaccountsuccess(){
					 
					 store.setValue("busistatus", "131072");
//						//去掉提交标识
						store._commitChanges(store.getAt(store.getCurcowindex()));
						store.getAt(store.getCurcowindex()).clearBusistatus();
						 setDisableed(true);
//						super.onOK();
//						Date d = new Date();
//						serviceenddate
//								.setFireChangeEventOnSetValue(true);
//						serviceenddate.setValue(d);
//						int index = store.getCurcowindex();
//						//
//						CommandSyncContainer list = new CommandSyncContainer();
//						
//						if(this.getS_cardno()!=null)
//						{
//						CommandSyncHasCcode hasccode = new CommandSyncHasCcode();
//						hasccode.setContinueorrollback(false);
//						hasccode.setS_cardno(this.getS_cardno());
//						hasccode.setPassword(this.getPassword());
//						list.add(hasccode);
//						
//						}
//						CommandSyncsql commandsql = new CommandSyncsql();
//						commandsql.getV().addAll(store._trySave(store.getCurcowindex()));
//						
//						
//						String icode = store.getValue(index, "icode").toString();
//						
//
//						
//						list.add(commandsql);
//						
//						if(this.getS_cardno()!=null)
//						{
//						CommandSyncAssociator associator = new CommandSyncAssociator();
//						associator.setContinueorrollback(false);
//						associator.setCcode(this.getS_cardno());
//						associator.setMode(4);
//						associator.setCurpaid(this.getYingshou());
//						associator.setIcode(Integer.parseInt(store.getValue("icode")+""));
//						list.add(associator);
//						
//				
//				 		}
//						else
//						{
//							String sql = "update s_service_po set busistatus='131072' where icode ='"
//							+ icode + "'";
//						commandsql.getV().add(sql);
//						}
//						
//						final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
//						.create(com.base.myproject.client.tools.GreetingService.class);
//						greetingService.SendCommandSync(list,
//						this);
//				
//						
//						//store.trySave(store.getCurcowindex());
//						
//						this.close();
//						 
				 }
//				 @Override
//					public void onFailure(Throwable caught) {
//					
//					 MessageBox.alert("错误", "网络出现连接失败！请重新提交。", null);
//					}
//
//					@Override
//					public void onSuccess(CommandSyncReturnObject result) {
//						
//						if(result.isB())
//						{
//							store.setValue("busistatus", "131072");
//							//去掉提交标识
//							store._commitChanges(store.getAt(store.getCurcowindex()));
//							store.getAt(store.getCurcowindex()).clearBusistatus();
//							 setDisableed(true);
//							Info.display("", "提交成功");
//						}
//						else
//						{
//							MessageBox.alert("错误", result.getMessage(), null);
//						}
//					}
			 };
			 
			 	
			 pd.setStore(store);
			 pd.setYingshou_g(pay_g.getValue()==null?0:pay_g.getValue().doubleValue());
			 pd.setYingshou(pay.getValue()==null?0:pay.getValue().doubleValue());
			 pd.setIcode(store.getValue("icode").toString());
			 pd.show();
			}
			
		
		
	}
	@Override
	public void Print() { 
		printer();
	}
	
	
	private void printer()
	{
		
		
		if(store.getValue("icode")==null)
		{
			MessageBox.alert("错误", "未选择打印单。", null);
			return;
		}
		String icode =store.getValue("icode").toString();
		PrintDialogX printdialog = new PrintDialogX("6001","&icode="+icode);
		printdialog.show();
		/*
		if(s_cardno.getValue()==null || s_cardno.getValue()=="")
		{
			MessageBox.alert("错误", "没找到会员卡号，请在 “会员管理” 模块进行打印", null);
			return;
		}
		*/
//		PrinterSync printersync = new PrinterSync();
//		printersync.setBcode(Env.getEnvbcode());
//		printersync.setPrintcode("service_1003");
//		printersync.setIcode(s_cardnothis.getValue()+"");
//		final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
//		.create(com.base.myproject.client.tools.GreetingService.class);
//		greetingService.getPrinterHtml(printersync,new AsyncCallback<String>(){
//
//			@Override
//			public void onFailure(Throwable caught) {
//				
//				
//			}
//
//			@Override
//			public void onSuccess(String result) {
//				Debug.printf(result.toString());
//				PrintDialog print = new PrintDialog("", "", result);
//			}
//			
//		});
	}
}
